package demo6;

import java.util.Arrays;
import java.util.Comparator;

class Student {
    public String name;
    public int age;

    public Student(int age, String name) {

        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }

}

class AgeCompartor implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        return o1.age - o2.age;
    }
}

class NameCompartor implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }


}


public class Test {

    public static void main(String[] args) {
        /*Student student1 = new Student(10, "zhangsan");
        Student student2 = new Student(1, "lisi");

        AgeCompartor ageCompartor = new AgeCompartor();
        System.out.println(ageCompartor.compare(student1,student2));

        NameCompartor nameCompartor = new NameCompartor();
        System.out.println(nameCompartor.compare(student1,student2));*/


        Student[] students = new Student[3];
        students[0] = new Student(10,"zhangsan");
        students[1] = new Student(1,"lisi");
        students[2] = new Student(12,"wangwu");

        System.out.println(Arrays.toString(students));
        Arrays.sort(students);
        System.out.println(Arrays.toString(students));
    }
}
